home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / php / pear / SOAP / Value.php < prev    next >
Encoding:
PHP Script  |  2006-04-07  |  6.6 KB  |  233 lines

  1. <?php
  2. /**
  3.  * This file contains the code for converting values between SOAP and PHP.
  4.  *
  5.  * PHP versions 4 and 5
  6.  *
  7.  * LICENSE: This source file is subject to version 2.02 of the PHP license,
  8.  * that is bundled with this package in the file LICENSE, and is available at
  9.  * through the world-wide-web at http://www.php.net/license/2_02.txt.  If you
  10.  * did not receive a copy of the PHP license and are unable to obtain it
  11.  * through the world-wide-web, please send a note to license@php.net so we can
  12.  * mail you a copy immediately.
  13.  *
  14.  * @category   Web Services
  15.  * @package    SOAP
  16.  * @author     Dietrich Ayala <dietrich@ganx4.com> Original Author
  17.  * @author     Shane Caraveo <Shane@Caraveo.com>   Port to PEAR and more
  18.  * @author     Chuck Hagenbuch <chuck@horde.org>   Maintenance
  19.  * @author     Jan Schneider <jan@horde.org>       Maintenance
  20.  * @copyright  2003-2005 The PHP Group
  21.  * @license    http://www.php.net/license/2_02.txt  PHP License 2.02
  22.  * @link       http://pear.php.net/package/SOAP
  23.  */
  24.  
  25. require_once 'SOAP/Base.php';
  26.  
  27. /**
  28.  * SOAP::Value
  29.  *
  30.  * This class converts values between PHP and SOAP.
  31.  *
  32.  * Originally based on SOAPx4 by Dietrich Ayala
  33.  * http://dietrich.ganx4.com/soapx4
  34.  *
  35.  * @access public
  36.  * @package SOAP
  37.  * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
  38.  * @author Dietrich Ayala <dietrich@ganx4.com> Original Author
  39.  */
  40. class SOAP_Value
  41. {
  42.     /**
  43.      *
  44.      *
  45.      * @var  string
  46.      */
  47.     var $value = null;
  48.  
  49.     /**
  50.      *
  51.      * @var  string
  52.      */
  53.     var $name = '';
  54.  
  55.     /**
  56.      *
  57.      * @var  string
  58.      */
  59.     var $type = '';
  60.  
  61.     /**
  62.      * Namespace
  63.      *
  64.      * @var  string
  65.      */
  66.     var $namespace = '';
  67.     var $type_namespace = '';
  68.  
  69.     var $attributes = array();
  70.  
  71.     /**
  72.      *
  73.      * @var string
  74.      */
  75.     var $arrayType = '';
  76.  
  77.     var $options = array();
  78.  
  79.     var $nqn;
  80.     var $tqn;
  81.  
  82.     /**
  83.      * Constructor.
  84.      *
  85.      * @param string $name        name of the soap-value {namespace}name
  86.      * @param mixed  $type        soap value {namespace}type, if not set an automatic
  87.      * @param mixed  $value       value to set
  88.      * @param array  $attributes  (optional) Attributes.
  89.      */
  90.     function SOAP_Value($name = '', $type = false, $value = null, $attributes = array())
  91.     {
  92.         // Detect type if not passed.
  93.         $this->nqn =& new QName($name);
  94.         $this->name = $this->nqn->name;
  95.         $this->namespace = $this->nqn->namespace;
  96.         $this->tqn =& new QName($type);
  97.         $this->type = $this->tqn->name;
  98.         $this->type_prefix = $this->tqn->ns;
  99.         $this->type_namespace = $this->tqn->namespace;
  100.         $this->value =& $value;
  101.         $this->attributes = $attributes;
  102.     }
  103.  
  104.     /**
  105.      * Serialize.
  106.      *
  107.      * @param SOAP_Base &$serializer  A SOAP_Base instance or subclass to serialize with.
  108.      *
  109.      * @return string  XML representation of $this.
  110.      */
  111.     function &serialize(&$serializer)
  112.     {
  113.         return $serializer->_serializeValue($this->value, $this->name, $this->type, $this->namespace, $this->type_namespace, $this->options, $this->attributes, $this->arrayType);
  114.     }
  115.  
  116. }
  117.  
  118. /**
  119.  * SOAP::Header
  120.  *
  121.  * This class converts values between PHP and SOAP. It is a simple
  122.  * wrapper around SOAP_Value, adding support for SOAP actor and
  123.  * mustunderstand parameters.
  124.  *
  125.  * Originally based on SOAPx4 by Dietrich Ayala
  126.  * http://dietrich.ganx4.com/soapx4
  127.  *
  128.  * @access public
  129.  * @package SOAP
  130.  * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
  131.  * @author Dietrich Ayala <dietrich@ganx4.com> Original Author
  132.  */
  133. class SOAP_Header extends SOAP_Value
  134. {
  135.     /**
  136.      * Constructor
  137.      *
  138.      * @param string  $name            name of the soap-value {namespace}name
  139.      * @param mixed   $type            soap value {namespace}type, if not set an automatic
  140.      * @param mixed   $value           value to set
  141.      * @param integer $mustunderstand  Zero or one.
  142.      * @param mixed   $attributes      (optional) Attributes.
  143.      */
  144.     function SOAP_Header($name = '', $type, $value,
  145.                          $mustunderstand = 0,
  146.                          $attributes = array())
  147.     {
  148.         if (!is_array($attributes)) {
  149.             $actor = $attributes;
  150.             $attributes = array();
  151.         }
  152.  
  153.         parent::SOAP_Value($name, $type, $value, $attributes);
  154.  
  155.         if (isset($actor)) {
  156.             $this->attributes['SOAP-ENV:actor'] = $actor;
  157.         } elseif (!isset($this->attributes['SOAP-ENV:actor'])) {
  158.             $this->attributes['SOAP-ENV:actor'] = 'http://schemas.xmlsoap.org/soap/actor/next';
  159.         }
  160.         $this->attributes['SOAP-ENV:mustUnderstand'] = (int)$mustunderstand;
  161.     }
  162.  
  163. }
  164.  
  165. /**
  166.  * SOAP::Attachment
  167.  * this class converts values between PHP and SOAP
  168.  * it handles Mime attachements per W3C Note on Soap Attachements at
  169.  * http://www.w3.org/TR/SOAP-attachments
  170.  *
  171.  *
  172.  * @access public
  173.  * @package SOAP
  174.  * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
  175.  */
  176. class SOAP_Attachment extends SOAP_Value
  177. {
  178.     /**
  179.      * Constructor
  180.      *
  181.      * @param    string  name of the soap-value <value_name>
  182.      * @param    mixed   soap header value
  183.      * @param    string namespace
  184.      */
  185.     function SOAP_Attachment($name = '', $type = 'application/octet-stream',
  186.                              $filename, $file = null)
  187.     {
  188.         global $SOAP_options;
  189.         if (!isset($SOAP_options['Mime'])) {
  190.             return PEAR::raiseError('Mail_mime is not installed, unable to support SOAP Attachements');
  191.         }
  192.         parent::SOAP_Value($name, null, null);
  193.  
  194.         $filedata = ($file === null) ? $this->_file2str($filename) : $file;
  195.         $filename = basename($filename);
  196.         if (PEAR::isError($filedata)) {
  197.             return $filedata;
  198.         }
  199.  
  200.         $cid = md5(uniqid(time()));
  201.  
  202.         $this->attributes['href'] = 'cid:'.$cid;
  203.  
  204.         $this->options['attachment'] = array(
  205.                                 'body'     => $filedata,
  206.                                 'disposition'     => $filename,
  207.                                 'content_type'   => $type,
  208.                                 'encoding' => 'base64',
  209.                                 'cid' => $cid
  210.                                );
  211.     }
  212.  
  213.     /**
  214.      * Returns the contents of the given file name as string
  215.      * @param string $file_name
  216.      * @return string
  217.      * @acces private
  218.      */
  219.     function &_file2str($file_name)
  220.     {
  221.         if (!is_readable($file_name)) {
  222.             return PEAR::raiseError('File is not readable ' . $file_name);
  223.         }
  224.         if (!$fd = fopen($file_name, 'rb')) {
  225.             return PEAR::raiseError('Could not open ' . $file_name);
  226.         }
  227.         $cont = fread($fd, filesize($file_name));
  228.         fclose($fd);
  229.         return $cont;
  230.     }
  231.  
  232. }
  233.